#
# CMake project for CVE-2019-2215
#

cmake_minimum_required(VERSION 3.12)

message(
        "
   ## # # ###     ### ###  #  ###     ### ###  #  ###
  #   # # #         # # # ##  # #       #   # ##  #
  #   # # ##  ### ### # #  #  ### ### ### ###  #  ###
  #   # # #       #   # #  #    #     #   #    #    #
   ##  #  ###     ### ### ### ###     ### ### ### ###
                                         @HackSysTeam
"
)


set(NDK_ROOT $ENV{HOME}/Android/Sdk/ndk/21.0.6113669)
set(ADB_PATH $ENV{HOME}/Android/Sdk/platform-tools/adb)


if (NOT DEFINED NDK_ROOT)
    if (DEFINED $ENV{NDK_ROOT})
        set(NDK_ROOT "$ENV{NDK_ROOT}")
    else ()
        message(FATAL_ERROR "Please define NDK_ROOT to point to your NDK path!")
    endif ()
endif ()


# Set the tool chain file
set(CMAKE_TOOLCHAIN_FILE ${NDK_ROOT}/build/cmake/android.toolchain.cmake)
set(ANDROID_ABI x86_64)
set(ANDROID_PLATFORM latest)


project(exploit)


add_executable(cve-2019-2215-trigger trigger.cpp)
add_executable(cve-2019-2215-exploit exploit.cpp)


add_custom_command(
        TARGET cve-2019-2215-trigger
        POST_BUILD
        COMMAND ${ADB_PATH} push cve-2019-2215-trigger /data/local/tmp > /dev/null
        COMMENT "Pushing cve-2019-2215-trigger to device"
        VERBATIM
)

add_custom_command(
        TARGET cve-2019-2215-exploit
        POST_BUILD
        COMMAND ${ADB_PATH} push cve-2019-2215-exploit /data/local/tmp > /dev/null
        COMMENT "Pushing cve-2019-2215-exploit to device"
        VERBATIM
)
